gh-117404: Add structured version info for compression modules - #150567
gh-117404: Add structured version info for compression modules#150567serhiy-storchaka wants to merge 10 commits into
Conversation
Documentation build overview
264 files changed ·
|
Add a number of constants in modules zlib, bz2, lzma, and compression.zstd, which provide information about the version of libraries that were used for building the module and that are actually loaded: * zlib.zlib_version -- an alias of zlib.ZLIB_RUNTIME_VERSION * zlib.ZLIB_VERSION_INFO * zlib.zlib_version_info * zlib.zlibng_version * zlib.ZLIBNG_VERSION_INFO * zlib.zlibng_version_info * bz2.bzlib_version * bz2.bzlib_version_info * lzma.LZMA_VERSION * lzma.lzma_version * lzma.LZMA_VERSION_INFO * lzma.lzma_version_info * compression.zstd.ZSTD_VERSION * compression.zstd.ZSTD_VERSION_INFO Make compression.zstd.zstd_version_info a named tuple.
f57fc45 to
76354de
Compare
|
@emmatyping, could you please look at this PR? |
…-versions-2 # Conflicts: # Doc/whatsnew/3.16.rst
|
Sorry for not reviewing sooner, will try to get to this tomorrow |
…-versions-2 # Conflicts: # Doc/whatsnew/3.16.rst
| The version string of the zlib library actually loaded by the interpreter. | ||
|
|
||
| .. versionadded:: 3.3 | ||
| .. versionchanged:: next |
There was a problem hiding this comment.
I think we should soft-deprecate the old one, otherwise we're inconsistent.
There was a problem hiding this comment.
Maybe later, when the new name became widespread.
| self.assertGreaterEqual(v.minor, 0) | ||
| self.assertGreaterEqual(v.patch, 0) | ||
|
|
||
| self.assertEqual(bz2.bzlib_version.split(',')[0], '%d.%d.%d' % v) |
There was a problem hiding this comment.
If I build with --with-bzip2=bzip2-rs:
test test_bz2 failed -- Traceback (most recent call last):
File "/home/stan/dev/cpython/Lib/test/test_bz2.py", line 1247, in test_bzlib_version
self.assertEqual(bz2.bzlib_version.split(',')[0], '%d.%d.%d' % v)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '1.1.0-libbz2-rs-sys-0.2.5' != '1.1.0'
- 1.1.0-libbz2-rs-sys-0.2.5
+ 1.1.0
| {0} | ||
| }; | ||
|
|
||
| static PyStructSequence_Desc zlib_version_desc = { |
There was a problem hiding this comment.
This was all copy pasted but not updated for bz2.
| int pos = 0; | ||
| unsigned int major = 0, minor = 0, revision = 0, subversion = 0; | ||
|
|
||
| sscanf(string, "%u.%u.%u.%u", &major, &minor, &revision, &subversion); |
There was a problem hiding this comment.
Yes, it can. Then we will get zeros for missing components. I think it is better than a hard error.
There was a problem hiding this comment.
I suggest a comment, to avoid people agents trying to fix this in the future.
| The version string of the zlib library actually loaded by the interpreter. | ||
|
|
||
| .. versionadded:: 3.3 | ||
| .. versionchanged:: next |
There was a problem hiding this comment.
Maybe later, when the new name became widespread.
| int pos = 0; | ||
| unsigned int major = 0, minor = 0, revision = 0, subversion = 0; | ||
|
|
||
| sscanf(string, "%u.%u.%u.%u", &major, &minor, &revision, &subversion); |
There was a problem hiding this comment.
Yes, it can. Then we will get zeros for missing components. I think it is better than a hard error.
Co-authored-by: Stan Ulbrych <stan@python.org> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* Register collect_bz2() and collect_lzma() in pythoninfo's collect_info(). * Do not assume a particular suffix of bz2.bzlib_version: libbz2-rs reports "1.1.0-libbz2-rs-sys-0.2.5" where bzip2 reports "1.0.8, 13-Jul-2019". * Document ZLIB_RUNTIME_VERSION and zlib_version as a single entry and tell in which version each of them was added. * Tell which fields the runtime *_version_info named tuples have by referring to their compile-time counterparts. * Remove a line duplicated when applying a suggestion for ZLIB_VERSION_INFO. * Fix indentation, alignment and line lengths of the added code. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Thank you for your review @StanFromIreland. I addressed your comments. |
StanFromIreland
left a comment
There was a problem hiding this comment.
Few little nits, but otherwise I like the API.
| Miscellaneous | ||
| ------------- | ||
|
|
||
| Information about the version of the bzip2 compression library in use |
There was a problem hiding this comment.
Maybe clarify what "in use" means, as in other places we distinguish compile/run time.
There was a problem hiding this comment.
It repeats existing phrase from zlib.rst. What is your suggestion?
There was a problem hiding this comment.
For zlib, we have both runtime and compile time constants, whereas here we only have runtime. It's not clear in the documentation if bzlib_version is runtime or compile time information. So, I suggest either clarifying here, or below in their documentation (but that's a little duplicative).
| }; | ||
|
|
||
| static PyStructSequence_Desc zstd_version_desc = { | ||
| "_zstd.zstd_version_info", /* name */ |
There was a problem hiding this comment.
Hmm, this will leak into the repr now, right? We could do like we have elsewhere:
Lines 2504 to 2505 in 999a046
There was a problem hiding this comment.
Unlike os.stat_result, the name of this type is not public. It cannot be used, because it conflicts with the name of the instance (like in sys.version_info and other precedences).
Interesting, Claude had the same complaint, but I convinced it.
| }; | ||
|
|
||
|
|
||
| PyDoc_STRVAR(bzlib_version__doc__, |
There was a problem hiding this comment.
| PyDoc_STRVAR(bzlib_version__doc__, | |
| PyDoc_STRVAR(bzlib_version_info__doc__, |
There was a problem hiding this comment.
Oh, this will need a lot of changes.
| }; | ||
|
|
||
| static PyObject * | ||
| make_zlibng_version(PyTypeObject *type, const char *string) |
There was a problem hiding this comment.
This is almost the same as make_zlib_version, it can be refactored.
* Explain in a comment why the result of sscanf() is not checked. * Merge make_zlib_version() and make_zlibng_version() into a single make_version_info(). * Rename the static names for the *_version_info named tuples, so that they match the name of the type. * Tell in the bz2 docs that bzlib_version and bzlib_version_info are the version of the library loaded at runtime, and that the version used for building the module is not available. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Add a number of constants in modules zlib, bz2, lzma, and compression.zstd, which provide information about the version of libraries that were used for building the module and that are actually loaded:
zlib.zlibng_versionzlib.zlibng_version_infoMake compression.zstd.zstd_version_info a named tuple.